﻿function ClientAddGroupLink()
{
    belongSite=document.getElementById("drpSelectSiteForGroupLink").options[document.getElementById("drpSelectSiteForGroupLink").selectedIndex].value;
    Url=Portal.CMS.GroupLink.GetAddGroupLinkUrl(belongSite).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}

function ClientSaveAddGroupLink()
{
    belongSite=document.getElementById("txtBelongSite").value;
    Subject=document.getElementById("txtGroupLink").value;
    GroupLinkItems=Portal.CMS.AddGroupLink.GetGroupLinkItemsObject().value;
    for(var Index=0;Index<GroupLinkItems.length;Index++)
    {
        if(document.getElementById("txtItemName_"+Index.toString())!=null)
        {
            GroupLinkItems[Index].GroupLinkItemName=document.getElementById("txtItemName_"+Index.toString()).value;
            GroupLinkItems[Index].Url=document.getElementById("txtItemUrl_"+Index.toString()).value;
            GroupLinkItems[Index].Target=document.getElementById("txtItemTarget_"+Index.toString()).value;
            GroupLinkItems[Index].Description=document.getElementById("txtItemDescription_"+Index.toString()).value;
            GroupLinkItems[Index].IndexOrder=document.getElementById("txtItemIndexOrder_"+Index.toString()).value;
        }
    }
    Portal.CMS.AddGroupLink.ServerSideAddGroupLink(belongSite,Subject,GroupLinkItems,ServerSideAddGroupLink_CallBack);
}


function ServerSideAddGroupLink_CallBack(response)
{
    if (response.error != null){
        alert(response.error);
        return;
    }
    
    RetValue=response.value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}

function ClientDeleteGroupLink(GroupLinkId)
{
    RetValue = Portal.CMS.GroupLink.ServerSideCheckAllowDelete(GroupLinkId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    Msg=Portal.CMS.GroupLink.GetConfirmDeleteMsg().value;
    if(confirm(Msg)==false)return;
    RetValue = Portal.CMS.GroupLink.ServerSideDeleteGroupLink(GroupLinkId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    FilterFunc()
}

function ShowClientUpdateUrlForm(GroupLinkId)
{
    Url=Portal.CMS.GroupLink.GetShowUpdateForm(GroupLinkId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}

function ClientSaveUpdateGroupLink(GroupLinkId) {
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    Subject=document.getElementById("txtGroupLink").value;
    GroupLinkItems=Portal.CMS.UpdateGroupLink.GetGroupLinkItemsObject().value;
    for(var Index=0;Index<GroupLinkItems.length;Index++)
    {
        if(document.getElementById("txtItemName_"+Index.toString())!=null) {
            GroupLinkItems[Index].GroupLinkItemId = document.getElementById("txtGroupLinkItemId_" + Index.toString()).value;
            GroupLinkItems[Index].GroupLinkItemName=document.getElementById("txtItemName_"+Index.toString()).value;
            GroupLinkItems[Index].Url=document.getElementById("txtItemUrl_"+Index.toString()).value;
            GroupLinkItems[Index].Target=document.getElementById("txtItemTarget_"+Index.toString()).value;
            GroupLinkItems[Index].IndexOrder=document.getElementById("txtItemIndexOrder_"+Index.toString()).value;
            GroupLinkItems[Index].Description=document.getElementById("txtItemDescription_"+Index.toString()).value;
        }
    }
    RetValue = Portal.CMS.UpdateGroupLink.ServerSideUpdateGroupLink(language, GroupLinkId,Subject,GroupLinkItems).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
}

function ShowPermissionFuncForm(GroupLinkId)
{
    Url= Portal.CMS.GroupLink.GetShowFormSetPermission(GroupLinkId).value;
     if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}



function FilterFunc()
{
    document.getElementById("divProcessing").innerHTML=Portal.CMS.GroupLink.GetProcessingText().value;
    setTimeout("RealFilterFunc()",10);
}


function RealFilterFunc()
{
    belongSite=document.getElementById("drpSelectSiteForGroupLink").options[document.getElementById("drpSelectSiteForGroupLink").selectedIndex].value;
    retValue= Portal.CMS.GroupLink.GetHtml(belongSite).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        document.getElementById("divProcessing").innerHTML="";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    document.getElementById("divGroupLinkMain").innerHTML=retValue;
}


function DetectSubjectLanguage(GroupLinkId) {
    language = document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    retValue = Portal.CMS.UpdateGroupLink.GetItems(language, GroupLinkId).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divContentItems").innerHTML = retValue;
}

function ClientSyncWithServer(ListNewsByGroupId) {
    if (confirm(Portal.CMS.ListNewsByGroup.GetConfirmSyncAllMsg().value) == false) {
        return;
    }
    document.getElementById("divProcessing").innerHTML = Portal.CMS.ListNewsByGroup.GetProcessingText().value;
    setTimeout("RealClientSyncWithServer('"+ListNewsByGroupId+"')", 10);
}

function RealClientSyncWithServer(ListNewsByGroupId) {
    rValue = Portal.CMS.ListNewsByGroup.ServerSideSyncWithServer(ListNewsByGroupId).value;
    document.getElementById("divProcessing").innerHTML = "";
    alert(rValue);
}